#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=110;
int edge[N][N];
int st[N];
int dist[N];
int n;
int prim()
{
	int ret=0;
	memset(dist,0x3f,sizeof(dist));
	memset(st,0,sizeof(st));
	dist[1]=0;
	for(int i=1;i<=n;i++)
	{
		int t=-1;
		for(int j=1;j<=n;j++)
		{
			if(!st[j] && (t==-1 || dist[t]>dist[j]))
			{
				t=j;
			}
		}
		ret+=dist[t];
		st[t]=1;
		for(int j=1;j<=n;j++)
			dist[j]=min(dist[j],edge[t][j]);
	}
	
	
	return ret;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>edge[i][j];
	
	cout<<prim()<<endl;
	
	return 0;
}
